'use strict';
/**
 * @name 账户基金账户页面Controller
 * @author zyf
 */
angular.module('metalabPartnerApp')
    .controller('FundCtrl', ['$scope', '$stateParams', '$state', 'MetaResources', 'MetaRemind', 'accountRecord', 'MetaSEO', 'MetaUtils', '$uibModal',
        function ($scope, $stateParams, $state, MetaResources, MetaRemind, accountRecord, MetaSEO, MetaUtils, $uibModal) {

            MetaSEO.setSEO('账户信息', '迈科技账户信息', '迈科技,迈科技账户,迈坦');

            if (accountRecord) {
                $scope.accountRecord = accountRecord[0];
            }

            /**
             * 分页参数
             */
            $scope.page = parseInt($stateParams.page);
            $scope.per = 10;

            /**
             * 获取账户列表
             */

            var min = ($scope.page - 1) * $scope.per + 1;
            $scope.recordPromise = MetaResources.accountRecord.query({
                    'userId': '_self',
                    '_range': MetaUtils.range(min, $scope.per),
                    '_sort': '-createdAt'
                },
                function (data, headers) {
                    $scope.accountRecords = data;
                    $scope.total = headers()['x-count'];
                }
            ).$promise;

            /**
             * 分页更新方法
             */
            $scope.update = function () {
                var min = ($scope.page - 1) * $scope.per + 1;
                $scope.recordPromise = MetaResources.accountRecord.query({
                    'userId': '_self',
                    '_range': MetaUtils.range(min, $scope.per),
                    '_sort': '-createdAt'
                }, function (data) {
                    $scope.accountRecords = data;
                }).$promise;

                $state.go('.', {page: $scope.page}, {notify: false});

            };

            $scope.exchangeFund = function () {
                var modalInstance = $uibModal.open({
                    animation: false,
                    templateUrl: 'views/account/fund-exchange-steps.html',
                    controller: ['$scope', '$uibModalInstance', function ($scope, $uibModalInstance) {
                        $scope.cancel = function () {
                            $uibModalInstance.dismiss('cancel');
                        };
                    }],
                    size: 'md'
                });
            }

        }]);
